package queue

import (
    "fmt"
    "github.com/segmentio/kafka-go"
    "log"
    "context"
)

var Writer *kafka.Writer

func InitKafka() {
    Writer = kafka.NewWriter(kafka.WriterConfig{
        Brokers: []string{"localhost:9092"},
        Topic:   "ginweb_topic",
    })

    log.Println("Kafka writer initialized")
}

func ProduceMessage(message string) error {
    err := Writer.WriteMessages(context.Background(), kafka.Message{
        Value: []byte(message),
    })
    if err != nil {
        return fmt.Errorf("failed to produce message: %w", err)
    }

    log.Println("Message produced successfully")
    return nil
}